package com.wuyan.locationdog.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.arcsoft.commonbase.bean.BannerItemBean
import com.arcsoft.commonbase.bean.DeviceBeanContent
import com.arcsoft.commonbase.ext.loadImage
import com.arcsoft.commonbase.ext.loadImageCircleCar
import com.blankj.utilcode.util.ActivityUtils
import com.wuyan.locationdog.R
import com.wuyan.locationdog.databinding.ItemCompassDogBinding
import com.wuyan.locationdog.help.gpsSignalImg
import com.wuyan.locationdog.help.gpsSignalText
import com.wuyan.locationdog.help.powerImg
import com.youth.banner.adapter.BannerAdapter


/**
 * 自定义布局，下面是常见的图片样式，更多实现可以看demo，可以自己随意发挥
 */
class ImageAdapter(var context: Context, mDatas: List<DeviceBeanContent>?) : BannerAdapter<DeviceBeanContent, BannerViewHolder>(mDatas) {
    //创建ViewHolder，可以用viewType这个字段来区分不同的ViewHolder
    override fun onCreateHolder(parent: ViewGroup, viewType: Int): BannerViewHolder {

        val mBinding = ItemCompassDogBinding.inflate(LayoutInflater.from(context), parent, false)

        return BannerViewHolder(mBinding)
    }

    override fun onBindView(holder: BannerViewHolder, data: DeviceBeanContent, position: Int, size: Int) {
        holder.mBinding.apply {
            dogImg.loadImageCircleCar(data.dog?.dogImg)
            speed.setText(data.speed + "km/h")
            power.setText(data.power + "%")
            powerImageView.setImageResource(powerImg(data.power?.toInt() ?: 0))

            gpsSignal.text = gpsSignalText(data.gpsSignal.toInt())
            gpsSignalImageView.setImageResource(gpsSignalImg(data.gpsSignal.toInt()))
            when (data.compositeDetailStatus) {
                1 -> {
                    ivStatus.setImageResource(R.mipmap.status_driver)
                }

                2 -> {
                    ivStatus.setImageResource(R.mipmap.status_stoping)
                }

                3 -> {
                    ivStatus.setImageResource(R.mipmap.status_alarm)
                }

                else -> {
                    ivStatus.setImageResource(R.mipmap.status_unline)
                }
            }

        }
    }

}

class BannerViewHolder(var mBinding: ItemCompassDogBinding) :
    RecyclerView.ViewHolder(mBinding.root) {}